package com.wsecar.sharelogin;

import android.content.Intent;
import android.os.Bundle;

import com.tencent.connect.common.Constants;
import com.wsecar.sharelogin.qq.bean.QQLoginInfo;
import com.wsecar.sharelogin.qq.bean.QQShareParamInfo;
import com.wsecar.sharelogin.qq.bean.QQUserInfo;
import com.wsecar.sharelogin.qq.listener.QQLoginCallBackListener;
import com.wsecar.sharelogin.qq.listener.QQShareResultListener;
import com.wsecar.sharelogin.qq.listener.QQUserInfoCallBackListener;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import android.util.Log;
import android.view.View;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        findViewById(R.id.qqlogin).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.i("TAG","======qqlogin===========");
                qqClickLogin();
            }
        });

        findViewById(R.id.qqShare).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                shareClickLogin();
            }
        });

        findViewById(R.id.qqShareQzne).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                qzneClickLogin();
            }
        });

        findViewById(R.id.wxLogin).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                wxLogin();
            }
        });
    }
/************************************************************QQ模块*****************************/
    /**
     * QQ 分享
     */
    public void shareClickLogin(){
        QQShareParamInfo shareParamInfo = ShareLoginHelper.getShareLoginHelper().builderShareParamsForDefault("明邦良","测试分享","https://www.baidu.com/img/bd_logo1.png","http://www.baidu.com","测试");
        ShareLoginHelper.getShareLoginHelper().qqShare(this, shareParamInfo, new QQShareResultListener() {
            @Override
            public void shareSuccess(Object object) {
                if (null == object ){
                    return;
                }
                Log.i("TAG","======shareSuccess=========="+object.toString());
            }

            @Override
            public void error(int code, String msg) {

            }

            @Override
            public void cancle() {

            }
        });

    }


    /**
     * QQ 分享
     */
    public void qzneClickLogin(){
        QQShareParamInfo shareParamInfo = ShareLoginHelper.getShareLoginHelper().builderShareParamsForDefault("明邦良","测试分享","https://www.baidu.com/img/bd_logo1.png","http://www.baidu.com","测试");
        ShareLoginHelper.getShareLoginHelper().qqShareQzone(this, shareParamInfo, new QQShareResultListener() {
            @Override
            public void shareSuccess(Object object) {
                if (null == object ){
                    return;
                }
                Log.i("TAG","======shareSuccess=========="+object.toString());
            }

            @Override
            public void error(int code, String msg) {

            }

            @Override
            public void cancle() {

            }
        });

    }


    /**
     * QQ登录
     */
    public void qqClickLogin(){
        ShareLoginHelper.getShareLoginHelper().login(this, true,new QQLoginCallBackListener() {
            @Override
            public void loginResult(QQLoginInfo loginInfo) {
                if (null == loginInfo){
                    return;
                }
                Log.i("TAG", "======qqlogin===========" + loginInfo.getAccess_token());
            }

            @Override
            public void error(int code, String msg) {

            }

            @Override
            public void cancle() {

            }
        }, new QQUserInfoCallBackListener() {
            @Override
            public void userInfo(QQUserInfo userInfo) {
                if (null == userInfo){
                    return;
                }
                Log.i("TAG", "======userInfo===========" + userInfo.getNickname());
            }

            @Override
            public void error(int code, String msg) {

            }

            @Override
            public void cancle() {

            }
        });
    }

    /************************************************************微信模块*****************************/
    /**
     * 微信登录
     */
    public void wxLogin(){

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        Log.d("TAG", "-->onActivityResult " + requestCode  + " resultCode=" + resultCode);
        if (requestCode == Constants.REQUEST_LOGIN ||
                requestCode == Constants.REQUEST_APPBAR) {
            ShareLoginHelper.getShareLoginHelper().onActivityResultData(requestCode,resultCode,data);
        }

        super.onActivityResult(requestCode, resultCode, data);
    }

}
